const {app, BrowserWindow, ipcMain} = require('electron')
const path = require('path')
const NODE_ENV = process.env.NODE_ENV

function createWindow() {
    //创建窗口
    const mainWindow = new BrowserWindow({
        frame: false,
        movable: true,
        title: 'Box_World',
        width: 1100,
        height: 600,


        webPreferences: {
            preload: path.join(__dirname, "preload.js"),
            webSecurity:false,
            nodeIntegration: true,
            contextIsolation: false,
        }
    });

    mainWindow.loadURL( NODE_ENV === 'development'
        ? 'http://localhost:5173'
        :`file://${path.join(__dirname, '../dist/index.html')}`);


    // 打开开发者工具
    if (NODE_ENV === 'development') {
        mainWindow.webContents.openDevTools()
    }
    ipcMain.on('window-all-min', () => {
        mainWindow.minimize()
    })
    ipcMain.on('window-all-max', () => {
        if (mainWindow.isMaximized()) {
            mainWindow.restore()

        } else {
            mainWindow.maximize()
        }
    })


}

app.whenReady().then(() => {
    createWindow();
    app.on('activate', function () {
        if (BrowserWindow.getAllWindows().length === 0) createWindow()
    })
})
ipcMain.on('window-all-closed', () => {
    if (process.platform !== 'darwin') {
        app.quit()
    }
})





